var userInfo = null;
var appointmentList = null;

$(document).ready(function () {
    ifLogin();
});

function ifLogin() {
    $.ajax({
        async: true,
        type: "post",
        url: "/ifLogin",
        contentType: 'application/json',
        dataType: "text",
        success: function (data) {
            var result = JSON.parse(data);
            userInfo = result.RESULT;
            if (result.SUCCESS) {
                console.log("用户已登录！");
                console.log(userInfo);
                afterLogin();
                getUserAppointment();
            } else {
                console.log(result);
                console.log(result.RESULT);
            }
        },
        error: function (data) {
            alert("请求失败");
        }
    });


    function afterLogin() {
        var userName = $("#userName");
        var sex = "先生";
        if (userInfo.sex == 0) {
            sex = "先生";
        } else {
            sex = "女士";
        }
        userName.text(userInfo.name + sex);
    }

}


function getUserAppointment(){
    $.ajax({
        async: true,
        type: "post",
        url: "/getUserAppointment",
        contentType: 'application/json',
        dataType: "text",
        success: function (data) {
            var result = JSON.parse(data);
            appointmentList = result.RESULT;
            if (result.SUCCESS) {
                console.log("已成功获取列表！");
                console.log(appointmentList);
                // afterLogin();
            } else {
                console.log(result);
                console.log(result.RESULT);
            }
        },
        error: function (data) {
            alert("请求失败");
        }
    });
}




